<template>
	<view>
		<news :newsData='newsData' @enter='navigateDetail'></news>
	</view>
</template>

<script>
	import newsComponents from '../../components/newsComponents.vue'
	export default {
		data() {
			return {
				newsData: []
			}
		},
		onLoad() {
			this.getNewsData()
		},
		methods: {
			//获取资讯数据
			async getNewsData() {
				const res = await uni.request({
					url: 'http://localhost:8082/api/getnewslist'
				})
				const data = res[1].data
				// console.log(data)
				if (data.status !== 0) {
					return uni.showToast({
						title: '获取数据失败'
					})
				} else {
					this.newsData = data.message
					console.log(this.newsData)
				}
			},
			//跳转资讯详情页面
			navigateDetail(id){
				uni.navigateTo({
					url:'/pages/news/newpages/newpages?id='+id
				})
			}
		},
		components: {
			'news': newsComponents
		}
	}
</script>

<style>

</style>
